using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Contracts.Contracts;
using Simple.Contracts.Models;
using Simple.Contracts.Models.Common;
using Simple.Contracts.Models.Common.Page;
using Simple.Repository.SimpleEntitys;
using Simple.WebAi.Authorizes;
using System.ComponentModel.DataAnnotations;

namespace Simple.WebAi.Controllers
{
    /// <summary>
    /// 老人信息
    /// </summary>
    [Route("api/elderly")]
    [AccountAuthorize]
    [ApiController]
    public class ElderlyController : ControllerBase
    {
        private readonly IElderlyService _elderlyInfoService;

        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="elderlyInfoService"></param>
        public ElderlyController(IElderlyService elderlyInfoService)
        {
            _elderlyInfoService = elderlyInfoService;
        }

        /// <summary>
        /// 获取老人列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("list")]
        [AccountAuthorize]
        public async Task<Result<PageDto<ElderlyInfoDto>>> List(ElderlyInfoListInput input)
        {
            return await _elderlyInfoService.List(input);
        }

        /// <summary>
        /// 保存老人信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("save")]
        [AccountAuthorize]
        public async Task<Result<long>> Save(ElderlyInfoSaveInput input)
        {
            return await _elderlyInfoService.Save(input);
        }

        /// <summary>
        /// 删除老人信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("delete")]
        [AccountAuthorize]
        public async Task<Result<bool>> Delete(ElderlyInfoDeleteInput input)
        {
            return await _elderlyInfoService.Delete(input);
        }

        /// <summary>
        /// 设置老人状态
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("set-status")]
        [AccountAuthorize]
        public async Task<Result<bool>> SetStatus(ElderlyInfoSetStatusInput input)
        {
            return await _elderlyInfoService.SetStatus(input);
        }

        /// <summary>
        /// 保存老人照护记录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("save-care-plan")]
        [AccountAuthorize]
        public async Task<Result<bool>> SaveElderlyCarePlan(SaveElderlyCarePlanInput input)
        {
            return await _elderlyInfoService.SaveElderlyCarePlan(input);
        }

        /// <summary>
        /// 获取老人照护记录
        /// </summary>
        /// <param name="elderlyId"></param>
        /// <returns></returns>
        [HttpGet("care-plan")]
        [AccountAuthorize]
        public async Task<Result<List<ElderlyCarePlanMissionDto>>> GetElderlyCarePlanMissionList([FromQuery][Required] long elderlyId)
        {
            return await _elderlyInfoService.GetElderlyCarePlanMissionList(elderlyId);
        }

        /// <summary>
        /// 获取员工照护的老人列表
        /// </summary>
        /// <param name="employeeId"></param>
        /// <returns></returns>
        [HttpGet("list/by-employeeId")]
        [AccountAuthorize]
        public async Task<Result<List<ElderlyCareInfoDto>>> GetElderlyByEmployeeId([Required]long employeeId)
        {
            return await _elderlyInfoService.GetElderlyByEmployeeId(employeeId);
        }

        /// <summary>
        /// 获取老人照护任务详情
        /// </summary>
        /// <param name="elderlyCarePlanMissionId"></param>
        /// <returns></returns>
        [HttpGet("care-plan-mission")]
        [AccountAuthorize]
        public async Task<Result<ElderlyCarePlanMissionDto?>> GetElderlyCarePlanMission([Required][FromQuery] long elderlyCarePlanMissionId)
        {
            return await _elderlyInfoService.GetElderlyCarePlanMission(elderlyCarePlanMissionId);
        }

        /// <summary>
        /// 保存老人照护记录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("save-care-record")]
        [AccountAuthorize]
        public async Task<Result<bool>> SaveElderlyCareRecord(SaveElderlyCareRecordInput input)
        {
            return await _elderlyInfoService.SaveElderlyCareRecord(input);
        }

        /// <summary>
        /// 获取老人照护记录列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("care-record-list")]
        [AccountAuthorize]
        public async Task<Result<PageDto<ElderlyCareRecordDto>>> GetElderlyCareRecordList(GetElderlyCareRecordListInput input)
        {
            return await _elderlyInfoService.GetElderlyCareRecordList(input);
        }
    }
}